fn main() {
    // -------------------- 生命周期标注 -------------------------
    // example 01
    // let x: &u16;
    // {
    //     let n = 100;
    //     n = &x
    // }
    // println!("{}", x);
    // example 02
    let longer_string = "Hello world!";
    let shorter_string = "hello world";
    println!("{}", get_longest_strict(longer_string, shorter_string));
    static CONST_VAR: &'static u8 = &100;
    println!("{}", CONST_VAR);
    // ------------------------- move ----------------------------
    // example 01
    let mut a = 0;
    let mut x = || {
        a += 1;
        println!("{}", a)
    };
    x();
    a += 2;
    println!("{}", a);
    // 输出1 3
    // -----------------------------------------------------------
    // example 02
    let mut a = 0;
    let mut x = move || { /* 在这里，变量a相当于被复制了一份（如examp 03所示），
                                        传进闭包，此时a与闭包外的变量a不再同步（约等于被放进了
                                        另一个线程） */
        a += 1;
        println!("{}", a)
    };
    x();
    a += 2;
    println!("{}", a);
    // 输出1 2
    // -----------------------------------------------------------
    // example 03
    let mut a = 0;
    // 这里闭包的类型变了
    let x = || {
        let mut b = a;
        b += 1;
        println!("{}", b)
    };
    x();
    a += 2;
    println!("{}", a);
    // 输出1 2
    // 来源：知乎 链接：<https://www.zhihu.com/question/626615299/answer/3254796089>
}

fn get_longest_strict<'a>(a: &'a str, b: &'a str) -> &'a str{
    if a.len() > b.len() {
        a
    } else {
        b
    }
}
